package com.ijunfu.detail.thread._01_Thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 *
 * @Title  : 
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/23 16:39
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
@Slf4j
public class _12Main {

    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            IntStream.range(0,10).forEach((idx)->{
                try {
                    TimeUnit.SECONDS.sleep(1L);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }

                log.info("{}", idx);
            });
        });

        // 启动线程
        t1.start();

        try {
            t1.join(TimeUnit.SECONDS.toMillis(5L));      // 等待子线程执行5秒后继续执行
        } catch (InterruptedException e) {
            t1.interrupt();
        }
        log.info("finish");
    }
}
